package com.wannengbang.cloudleader.mine.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.cloudleader.R;
import com.wannengbang.cloudleader.bean.DirectorListBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 董事列表
 */
public class DirectorListAdapter extends RecyclerView.Adapter<DirectorListAdapter.ViewHolder> {

    private List<DirectorListBean.DataBean.ItemListBean> listsBeans;
    private Context context;
    private onCallBackListener onCallBackListener;

    public void setOnCallBackListener(DirectorListAdapter.onCallBackListener onCallBackListener) {
        this.onCallBackListener = onCallBackListener;
    }

    public DirectorListAdapter(List<DirectorListBean.DataBean.ItemListBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_director_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        DirectorListBean.DataBean.ItemListBean dataBean = listsBeans.get(position);
        holder.tvName.setText(dataBean.getName());
        holder.tvStartCount.setText("董事星级：" + dataBean.getStar_count() + "星");
        if (!TextUtils.isEmpty(dataBean.getMobile()) && dataBean.getMobile().length() == 11) {
            String mobile = dataBean.getMobile().substring(0, 3) + "****" + dataBean.getMobile().substring(7, 11);
            holder.tvMobile.setText("手机号：" + mobile);
        } else {
            holder.tvMobile.setText("手机号：" + dataBean.getMobile());
        }
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_mobile)
        TextView tvMobile;
        @BindView(R.id.tv_start_count)
        TextView tvStartCount;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface onCallBackListener {
        void onCallBack(int type, int position);
    }
}
